package _07线程池案例;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {



        long start = System.currentTimeMillis();
        ExecutorService pool = Executors.newFixedThreadPool(3);
        MyCallable c1 = new MyCallable(1,10000);
        MyCallable c2 = new MyCallable(10001,20000);

        Future<Integer> s1 = pool.submit(c1);
        Future<Integer> s2 = pool.submit(c2);
        long end = System.currentTimeMillis();
        System.out.println(s1.get());
        System.out.println(s2.get());
        System.out.println(s1.get()+s2.get());


        System.out.println("本次计算耗时"+(end-start)+"ms");
    }
}
